package com.campus.web.controller;


import com.campus.app.service.FeedbacksService;
import com.campus.commons.entity.FeedType;
import com.campus.commons.entity.Feedback;
import com.campus.commons.utils.MyPage;
import com.campus.commons.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.validation.Valid;

/**
 * <p>
 * 问题反馈 前端控制器
 * </p>
 *
 * @author Rin
 * @since 2020-12-24
 */
@RestController
@RequestMapping("/feedback")
public class FeedbackController {

    @Autowired
    private FeedbacksService feedbacksService;
    // 获取所有问题反馈
    @PostMapping("/all")
    public Result getAllFeedbacks() {
        return feedbacksService.getAllFeedbacks(new MyPage<>(1,10));
    }


    @PostMapping("/search")
    public Result getFeedbacks(MyPage<Feedback> myPage,Feedback feedback, FeedType feedType) {
        feedType.setName(feedType.getName()!=null&&feedType.getName().trim().length()==0?null:feedType.getName());
        feedback.setFeedType(feedType);
        myPage.setData(feedback);
        return feedbacksService.getFeedbacks(myPage);
    }
    @PostMapping("/del")
    public Result delFeedback(Integer id) {
        return feedbacksService.delFeedback(id);
    }

    @PostMapping("/dispose")
    public Result disposeFeedback(Integer id) {
        return feedbacksService.disposeFeedback(id);
    }

    @PostMapping("/add")
    @ApiOperation("添加反馈信息：")
    public Result addFeedback(@Valid Feedback feedback) {
        return feedbacksService.addFeedback(feedback);
    }

    @GetMapping("/")
    public ModelAndView toIndex(Model model) {
        ModelAndView modelAndView = new ModelAndView();
        model.addAttribute("feedType", FeedType.feeds.values());
        modelAndView.setViewName("feedback/index");
        return modelAndView;
    }
}

